package 设计模式.创建型模式.demo04原型模式.demo03深拷贝;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import 设计模式.创建型模式.demo04原型模式.demo02官方实现.Cat;

/**
 * @author: 王富贵
 * @description: 树类
 * @createTime: 2022/11/07 16:05
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class Tree implements Cloneable{
    private String name;
    public String likeFood;


    @Override
    protected Object clone() throws CloneNotSupportedException {
        Tree cloneTree =(Tree) super.clone();
        //深拷贝需要新创建，否则就是浅拷贝
        cloneTree.name = new String(name);
        return cloneTree;
    }
}
